package com.taotao.manage.controller;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.taotao.manage.service.ItemCatService;
import com.taotao.manage.viewObject.ItemCatForTree;

@Controller
@RequestMapping("item/cat")
public class ItemCatController {

	@Autowired
	private ItemCatService  itemCatService;
	
	@GetMapping
	public ResponseEntity<List<ItemCatForTree>> queryItemCatList(@RequestParam(value="id",defaultValue="0")Long parentId){
		try {
			ItemCatForTree itemCat = new ItemCatForTree();
			itemCat.setParentId(parentId);
			itemCat.setStatus(1);
			List<ItemCatForTree> itemCats = itemCatService.queryListByWhere(itemCat);
			if(CollectionUtils.isEmpty(itemCats)){
				return ResponseEntity.notFound().build();
			}
			return ResponseEntity.ok(itemCats);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
		}
	}
	
}
